

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;
import java.io.Serializable;

public class FilledTriangleObject extends ShapeObject implements Serializable{

	public boolean invertedTriangle;
	public FilledTriangleObject(Point startingMousePosition,Point endingMousePosition, Color color, boolean inv) {
		super(startingMousePosition, endingMousePosition, color);
		invertedTriangle = inv;
	}

	protected DrawingCanvas canvas;

	
	public void drawShape(DrawingCanvas canvas){
	
		int x = startingMousePosition.x;
		int y = startingMousePosition.y; 
		int width = endingMousePosition.x-startingMousePosition.x; 
		int height = endingMousePosition.y-startingMousePosition.y;
		Point topPoint = new Point();
		Point leftPoint = new Point();
		Point rightPoint = new Point();
		
		topPoint.x = x + width/2;
		leftPoint.x = x;
		rightPoint.x = x + width;
		
		if(invertedTriangle){
			topPoint.y = y + height;
			leftPoint.y = y;
			rightPoint.y = y;
		}
		else{
			topPoint.y = y;
			leftPoint.y = y + height;
			rightPoint.y = y + height;
		}
		
		int[] xarray = {topPoint.x, leftPoint.x, rightPoint.x};
		int[] yarray = {topPoint.y, leftPoint.y, rightPoint.y};
		
	    Graphics iBGraphics = canvas.getImageBufferGraphics();
	    iBGraphics.setColor(this.color);
	    iBGraphics.fillPolygon(new Polygon(xarray, yarray, 3));
	      
	    canvas.repaint();
	}

	public boolean isResizeable() {
		return true;
	}
}
